<template>
  <div>
    <mainFrame>
      <div slot='content'>
        <div class="top-title">
          换相记录
        </div>
        <div style="margin: 10px 0;">
          <el-button type="primary" @click="back" icon="el-icon-back">返回</el-button>
        </div>
        <div class="top" style="margin: 10px 0;">
          <el-date-picker v-model="dateRange" type="daterange" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" @change="getMachineInfo">
          </el-date-picker>
        </div>
        <div style="margin: 10px 0;">
          <el-row type="flex">
            <el-col :span="3">归属地：{{ item.location }}</el-col>
            <el-col :span="3">台区号：{{ item.areaNo }}</el-col>
          </el-row>
        </div>
        <el-table :data="records" border style="width: 100%" stripe>
          <!-- <el-table-column prop="id" label="id" width="50">
          </el-table-column> -->
          <el-table-column prop="machineNo" label="换相器" width="100">
          </el-table-column>
          <el-table-column prop="time" label="时间" width="200">
          </el-table-column>
          <!-- <el-table-column prop="FromL" label="自" width="200">
            <template slot-scope="scope">
              <span v-if="scope.row.FromL==0">A</span>
              <span v-if="scope.row.FromL==1">B</span>
              <span v-if="scope.row.FromL==2">C</span>
              <span v-if="scope.row.FromL==3">D（脱网状态）</span>
            </template>
          </el-table-column> -->
          <el-table-column prop="ToL" label="换相至" width="200">
            <template slot-scope="scope">
              <span v-if="scope.row.ToL==0">A</span>
              <span v-if="scope.row.ToL==1">B</span>
              <span v-if="scope.row.ToL==2">C</span>
              <span v-if="scope.row.ToL==3">D（脱网状态）</span>
            </template>
          </el-table-column>
          <el-table-column prop="I" label="负载电流" width="200">
            <template slot-scope="scope">
              {{ scope.row.I ? scope.row.I : 0}}A
            </template>
          </el-table-column>
        </el-table>
        <div style="margin: 10px 0;">
          <el-pagination layout="prev, pager, next" :page-size="pageSize" :current-page.sync="currentPage" :page-count="totalPage" @current-change="pageChange">
          </el-pagination>
        </div>
      </div>
    </mainFrame>
  </div>
</template>
<script>
import mainFrame from '@/components/mainFrame'
import utils from '../ttJs/utils.js'
export default {
  components: {
    mainFrame
  },
  data() {
    return {
      dateRange: [new Date(), new Date()],
      item: [],
      records: [],
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      currentPage: 0,
      pageSize: 0,
      totalPage: 0
    };
  },
  mounted: function() {
    this.getTaiquInfo();
    this.getMachineInfo();
  },

  methods: {
    getTaiquInfo() {
      var self = this;
      if (utils.validateData(self.$route.query.id)) {
        var id = self.$route.query.id;
        var url = '/yitai/admin/areaInfo';
        var params = { id: id }
        var success = function(response) {
          self.item = response.info;
        }
        var fail = function() {
          utils.fail('加载失败')
        }
        var complete = function() {}
        utils.requestLoading(url, params, success, fail, complete)
      }
    },
    getMachineInfo() {
      var self = this;
      if (utils.validateData(self.$route.query.id)) {
        var id = self.$route.query.id;
        var url = '/yitai/admin/areaChangeRecord';
        var start = self.dateRange[0].getFullYear() + '-' + (self.dateRange[0].getMonth() + 1) + '-' + self.dateRange[0].getDate() + ' 00:00:00';
        var end = self.dateRange[1].getFullYear() + '-' + (self.dateRange[1].getMonth() + 1) + '-' + self.dateRange[1].getDate() + ' 23:59:59';
        var params = {
          areaId: id,
          startDate: start,
          endDate: end,
          page: this.currentPage
        }
        var success = function(response) {
          self.records = response.info;
          self.currentPage = response.page;
          self.pageSize = response.size;
          self.totalPage = response.total;
        }
        var fail = function() {
          utils.fail('加载换相记录失败');
        }
        var complete = function () {};
        utils.requestLoading(url, params, success, fail, complete);
      }
    },
    back() {
      window.history.back();
    },
    pageChange(pageNum) {
      this.currentPage = pageNum;
      this.getMachineInfo();
    }
  },
}

</script>
<style scoped rel="stylesheet/scss" lang="scss">
.page {
  position: relative;
  overflow: hidden;
  padding: 20px;
}

.top-title {
  font-size: 18px;
  font-weight: bold;
  padding: 0 20px;
}

el-col {
  vertical-align: center;
}

</style>
